#This script is designed to deal with the string of file or path or dir
import os.path

#Check path or not
def pathok(path):
    return os.path.exists(path)

#Check file or not
def fileok(path):
    return os.path.isfile(path)

#Check dir or not
def dirok(path):
    return os.path.isdir(path)

#Split the filename from the path string
def splitfile(path):
    if fileok(path):
        return os.path.split(path)[1]
    else:#it is not a file
        return 0

#Split the path from the path string
def splitpath(path):
    if fileok(path):
        return os.path.split(path)[0]
    else:#it is not a file
        return 0

def mkdir(path):
    import os
    path=path.strip()
    path=path.rstrip("\\")
    isExists=os.path.exists(path)
    if not isExists:
        os.makedirs(path)
        print path,' finished!'
        return True
    else:
        print path+' exists!'
        return False

#How to use:

# pt=raw_input('please input a string:')
# r=splitfile(pt)
# if r==0:
#     print 'Sorry it is not a file...'
# else:
#     print 'The filename of ',pt,' is ',r
# r=splitpath(pt)
# if r==0:
#     print 'Sorry it is not a file...'
# else:
#     print 'The path of ',pt,' is ',r

'''
please input a string:F:/code/py/KNN.py
The filename of  F:/code/py/KNN.py  is  KNN.py
The path of  F:/code/py/KNN.py  is  F:/code/py
'''

# pt=raw_input('please input a string:')
# if pathok(pt):
#     print pt,'is an exists path'
# if fileok(pt):
#     print pt,'is an exists file'
# if dirok(pt):
#     print pt,'is an exists dir'
# print 'Now the programming is shuttng down...'

'''
please input a string:F:/code
F:/code is an exists path
F:/code is an exists dir
Now the programming is shuttng down...
'''